#pragma once
#include <btBulletDynamicsCommon.h>
#include "MyMotionState.h"
#include <map>
#include "NodeInfo.h"

using namespace std;

#define BIT(x) (1<<(x))
enum collisiontypes {
	COL_NOTHING = 0, //<Collide with nothing
	COL_BOUND = BIT(0), //<Collide with bound
	COL_AIRCRAFT = BIT(1), //<Collide with aircraft
	COL_CHECKPOINT = BIT(2), //<Collide with check point
};

const int boundCollidesWith = COL_AIRCRAFT;
const int aircraftCollidesWith = COL_BOUND | COL_CHECKPOINT;
const int checkpointCollidesWith = COL_AIRCRAFT;

class PhysicsWorld
{
public:
	~PhysicsWorld(void);
	static PhysicsWorld * GetInstance();
	void ExitPhysics();
	void UpdatePhysics(float etime);
	btCollisionShape * ReadModelFromFile(char *filePath);
	btRigidBody * CreateRigidBody(float mass, btTransform *trans, btCollisionShape *a_shape, short group, short mask, Ogre::SceneNode *node = NULL, int id = -1, string name = "");
	btRigidBody * GetRigidBody(int id);

private:
	PhysicsWorld(void);
	void InitPhysics();

	static PhysicsWorld*					m_instance;
	btDiscreteDynamicsWorld*				m_dynamicsWorld;
	btDefaultCollisionConfiguration*		m_collisionConfiguration;
	btCollisionDispatcher*					m_dispatcher;
	btBroadphaseInterface*					m_overlappingPairCache;
	btSequentialImpulseConstraintSolver*	m_solver;
	btAlignedObjectArray<btCollisionShape*>	m_collisionShapes;
	std::map<int, btRigidBody*>				m_bodyMap;
};

